// 价格过滤
export const filterPrice = price => price.toFixed(2);

// 时间过滤 时间戳转时间
export const fliterTime = (t) => {
    t = Number(t);
    if (t == null) {
        return null;
    }
    let date = new Date(t);
    let y = 1900 + date.getYear();
    let m = "0" + (date.getMonth() + 1);
    let d = "0" + date.getDate();
    return y + "." + m.substring(m.length - 2, m.length) + "." + d.substring(d.length - 2, d.length);
}

// 倒计时
export const countTime = (t) => {
    // 获取当前时间戳
    var now = new Date().getTime();

    // 设置截止时间戳
    var endDate = new Date(t).getTime();
    // 时间差
    var leftTime = endDate - now;
    // console.log(new Date(leftTime).toLocaleString())
    if (leftTime >= 0) {
        var d=Math.floor(leftTime/1000/3600/24)
        var h = Math.floor(leftTime / 1000 / 60 / 60 % 24)+d*24;
        h = h < 10 ? "0" + h : h;
        var m = Math.floor(leftTime / 1000 / 60 % 60);
        m = m < 10 ? "0" + m : m;
        var s = Math.floor(leftTime / 1000 % 60);
        s = s < 10 ? "0" + s : s;
    }
    return { leftTime,h, m, s}

}
